import java.io.IOException;

public class Main{

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		java.io.BufferedReader r = new java.io.BufferedReader(
				new java.io.InputStreamReader(System.in));
		while (true) {
			int num = Integer.parseInt(r.readLine().trim());
			if (num == -1) {
				break;
			}
			int sum = 0;
			int avg;
			int[] arr = new int[num];
			for (int i = 0; i < num; i++) {
				arr[i] = Integer.parseInt(r.readLine().trim());
				sum += arr[i];
			}
			int count = 0;
			if (sum % num == 0) {
				avg = sum / num;
				for (int i = 0; i < arr.length; i++) {
					if (arr[i] > avg) {
						count += (arr[i] - avg);
					}
				}
				System.out.println(count);
			} else {
				System.out.println(-1);
			}

		}
	}

}
